﻿namespace Frameworks
{
    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using Object = UnityEngine.Object;
    
    internal class LogInfo
    {
        public Object Source { get; private set; }
        public string Channel { get; private set; }
        public string Message { get; private set; }
        public LogType Type { get; private set; }
        public List<LogStackFrame> Callstack { get; private set; }
        public string RelativeTimeStampAsString { get; private set; }
        public string AbsoluteTimeStampAsString { get; private set; }

        private double _relativeTimeStamp;
        private DateTime _absoluteTimeStamp;
        
        public LogInfo(Object source, string channel, LogType type, List<LogStackFrame> callstack, object message, params object[] par)
        {
            Source = source;
            Channel = channel;
            Type = type;
            Message = "";

            var messageString = message as string;
            if (messageString != null)
            {
                if (par.Length > 0)
                {
                    Message = string.Format(messageString, par);
                }
                else
                {
                    Message = messageString;
                }
            }
            else
            {
                if (message != null)
                {
                    Message = message.ToString();
                }
            }

            Callstack = callstack;
            _relativeTimeStamp = Debugger.GetRelativeTime();
            _absoluteTimeStamp = DateTime.UtcNow;

            RelativeTimeStampAsString = string.Format("{0:0.0000}", _relativeTimeStamp);
            AbsoluteTimeStampAsString = _absoluteTimeStamp.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);
        }
    }
}
